package com.gobang.controller;

import com.gobang.domain.dto.PageRequest;
import com.gobang.domain.vo.PageData;
import com.gobang.domain.vo.Result;
import com.gobang.domain.vo.points.PointsInfoVO;
import com.gobang.domain.vo.points.PointsLogItemVO;
import com.gobang.service.PointsService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/user/points")
@RequiredArgsConstructor
public class PointsController {

    private final PointsService pointsService;

    @GetMapping
    @PreAuthorize("hasAnyRole('USER','ADMIN')")
    public Result<PointsInfoVO> getCurrentPoints() {
        PointsInfoVO pointsInfo = pointsService.getCurrentPoints();
        return Result.success(pointsInfo);
    }

    @GetMapping("/logs")
    @PreAuthorize("hasAnyRole('USER','ADMIN')")
    public Result<PageData<PointsLogItemVO>> getCurrentUserPointsLogs(@Valid PageRequest pageRequest) {
        PageData<PointsLogItemVO> pageData = pointsService.getPointsLogsForCurrentUser(pageRequest);
        return Result.success(pageData);
    }
}
